package org.liubility.server.commons.config;


import com.jdragon.common.utils.SystemUtils;
import org.liubility.server.commons.property.PathProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: Jdragon
 * @email: 1061917196@qq.com
 * @Date: 2020.05.13 21:29
 * @Description:
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    PathProperty pathProperty;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String basePath = SystemUtils.isWindows() ? pathProperty.getWindowsPath() : pathProperty.getLinuxPath();

        registry.addResourceHandler(pathProperty.getImagesUrl() + "**")
                .addResourceLocations("file:" + basePath + pathProperty.getImagesUrl());

        registry.addResourceHandler(pathProperty.getCodeUrl() + "**")
                .addResourceLocations("file:" + basePath + pathProperty.getCodeUrl());

    }
    @Bean
    public ExecutorService executorService() {
        return Executors.newFixedThreadPool(10);
    }
}
